package com.linran.javaweb.config;

import com.linran.javaweb.client.UserServiceClient;
import feign.Feign;
import feign.httpclient.ApacheHttpClient;
import feign.jackson.JacksonDecoder;
import feign.jackson.JacksonEncoder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * feign配置类
 * @author lin
 * @date 2020-06-07 20:40
 */
@Configuration
public class FeignConfig {

    @Bean
    public UserServiceClient userServiceClient(@Value("${base.url}") String baseUrl){
        return feignClientBuilder(UserServiceClient.class, baseUrl);
    }

    public <T>T feignClientBuilder(Class<T> clz, String url){
        return Feign.builder().client(new ApacheHttpClient())
                .encoder(new JacksonEncoder())
                .decoder(new JacksonDecoder()).target(clz, url);
    }
}
